<template>
  <div class="park">
    <van-nav-bar title="停哪儿" left-text="返回" right-text="查询" left-arrow @click-left="back" @click-right="parklist"/>
    
    <div @click="parkdetail(item)" class="parklist" v-for="item in list" :key=item.id>
      <div class="parklist-address">
        <div class="parklist-address-name">{{item.parkName}}</div>
        <div>现空车位：{{item.vacancy}}个</div>
        <div>具体地址：{{item.address}}</div>
        <div>收费标准：{{item.rates}}元/时
        <span>距离：{{item.distance}}米</span>
        </div>
      </div>
      
    </div>
  </div>
  
</template>

<script>
import mixin from  "@/mixin/flag";
import{parkview} from "./Service"
export default {
    data(){
        return {
            list:[]
        }
    },
    mixins:[mixin],
    methods:{
    back(){
      this.$router.go(-1);
    },
    parklist(){
      this.$router.push('/park/list')
    },
    parkdetail(item){
      // console.log(item.id);
      this.$router.push(`/park/detail/${item.id}`)
    }
  },
  async created(){
    let res = await parkview();
      if(res.status==200){
        res.data.rows=res.data.rows.sort(function(a,b){
          return a.distance-b.distance
        })
        this.list=res.data.rows;
        // console.log(this.list);
      }
  }
}
</script>

<style lang="scss" scoped>
.parklist{
  
  width: 100%;
  height: 120px;
  border-bottom: 1px solid #555;
    padding-top:15px;
    padding-left:20px;
    .parklist-address{
      font-size: 14px;
      line-height: 26px;
      .parklist-address-name{  
        font-size: 16px;
        font-weight: bold;
      }
      span{
        margin-left: 120px;
      }
      
    }
    
  }

    
</style>